package com.sunni.mapper;

import com.sunni.entity.Order;
import com.sunni.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrderMapper {

//    @Select("select o.*,o.id oid,u.* from `order` o,user u where o.uid=u.id")
//  day16-05: 一对一：方式二：@One = <association>
    @Select("select * from `order`")
    @Results({
            // order基本属性
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "orderTime",column = "order_time"),
            @Result(property = "total",column = "total"),

            //内部类属性
            @Result( // 相当于<association>
                    javaType = User.class, // 内部类的数据类型
                    property = "user", // 内部类属性在order类的属性名

                    /*使用另一个方法，查询关联的user信息，并用那个方法封装 内部类user属性*/
                    column = "uid", // 把uid当成参数，传给下面的方法
                    one = @One(select = "com.sunni.mapper.UserMapper.selectById") // 用这个方法 封装成user属性
            )
    })
    List<Order> selectAll();
    //  day16-04: 一对一：方式一。
/*    @Results({
            @Result(id = true,property = "id", column = "oid"),
            @Result(property = "orderTime", column = "order_time"),
            @Result(property = "total", column = "total"),
            @Result(property = "user.id",column = "uid"),
            @Result(property = "user.name",column = "name"),
            @Result(property = "user.address",column = "address"),
            @Result(property = "user.birthday",column = "birthday")
    })*/

/*day16-06 : 一对多  List<Order>订单集合属性 封装调用这个方法orderList*/
    @Select("select * from `order` where uid=#{uid}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "orderTime",column = "order_time"),
            @Result(property = "total",column = "total")
    })
    List<Order> selectByUid(Integer uid);
}
